//
//  IDCardValidator.swift
//  User
//
//  Created by 郑林琴 on 2017/1/11.
//  Copyright © 2017年 IB. All rights reserved.
//

import UIKit


/// 身份证验证
public class IDCardValidator: NSObject, Validator {
    
    public func validate(txt: String?) -> Bool {
        
        guard let txt = txt else {
            return false
        }
        
        if txt.isEmpty {
            return false
        }
        
        let formate = "^[1-9]\\d{14}$|^[1-9]\\d{16}(\\d|X|x)$"
        let predicate = NSPredicate(format: "SELF MATCHES %@", formate)
        return predicate.evaluate(with: txt)
    }
}
